package net.monare.mifss.evn;

import com.vaadin.ui.Button;
import com.vaadin.ui.Notification;
import net.monare.mifss.MifssHolder;
import net.monare.mifss.MifssMessages;
import net.monare.mifss.admin.ui.win.ConfigureStorageWindow;
import net.monare.mifss.exceptions.StorageServiceException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by jernej on 4/10/14.
 */

public class UnlockStorageListener extends BasicMifssListener implements Button.ClickListener {

    private String storageSetName;
    private ConfigureStorageWindow parent;



    public UnlockStorageListener(String storageSetName, ConfigureStorageWindow parent) {
        this.storageSetName = storageSetName;
        this.parent = parent;
    }

    @Override
    public void buttonClick(Button.ClickEvent event) {

        try {
            getMifssHolder().getStorageService().lockStorageSet(storageSetName, getUserName(), false);

        } catch (StorageServiceException e) {
            Notification.show(MifssMessages.getMessage("sys.error.unlock.storage.set") + " : " + e.getMessage());
        }

        // redraw
        parent.resetMiddlePane(null);
        parent.resetLeftPane();

    }
}
